#include <amxmodx>
#include <items>
#include <fakemeta>

new PLUGIN_NAME[] 	= "UM Item: Bullet Proof Vest"
new PLUGIN_AUTHOR[] 	= "Cheap_Suit"
new PLUGIN_VERSION[] 	= "1.0"

new bool:g_BPVest[33] 
public plugin_init() 
{
	register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR)
	register_item("Bullet Proof Vest", "Take no damage from the stomach or the chest", 2500)
	register_forward(FM_TraceLine, "FW_TraceLine")
}

public client_connect(id) {
	g_BPVest[id] = false
}

public Enable_Item(id) {
	g_BPVest[id] = true
}

public Disable_Item(id) {
	g_BPVest[id] = false
}

public FW_TraceLine(Float:v1[3], Float:v2[3], noMonsters, id) 
{  
	if(!is_user_connected(id) || !is_user_alive(id)) {
		return FMRES_IGNORED
	}
	
	new Target = get_tr(TR_pHit)
	if(!is_user_connected(id) || !is_user_alive(Target)) {
		return FMRES_IGNORED
	}
	
	if(!g_BPVest[Target]) {
		return FMRES_IGNORED
	}

	new HitGroup = get_tr(TR_iHitgroup)	
	if((HitGroup == HIT_CHEST || HitGroup == HIT_STOMACH)) {
		set_tr(TR_flFraction, 1.0)
	}
	return FMRES_IGNORED
}  
